package prototype;

import org.junit.Test;
import prototype.deep.Student;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

//import prototype.nodesign.Student;

public class DemoTest2 {

    @Test
    public void test1() throws InterruptedException, CloneNotSupportedException {
        Student studentA = new Student("学生", 1);
        Student studentB = (Student) studentA.clone();
        System.out.println("StudentA == StudentB : " + (studentA == studentB));
        System.out.println("StudentA.course == StudentB.course : " + (studentA.getCourse() == studentB.getCourse()));

        long start =  new Date().getTime();
        List<Student> students = new ArrayList<>();
        Student student = new Student("学生", 1);
        for(int i=0; i<10; i++) {
            Student studentNew = (Student) student.clone();
            studentNew.setName("学生" +  (i + 1));
            students.add(studentNew);
        }
        long end =  new Date().getTime();
        System.out.println("创建10个对象共花费了时间:" + (end -start) + " ms");
        for (Student one: students) {
            System.out.println(one.toString());
        }

        //如果学生6,转班到班级2，并且多学了一门物理
        for (Student one: students) {
            if(one.getName().equals("学生6")){
                one.setClassid(2);
                one.getCourse().add("物理");
            }
        }
        for (Student one: students) {
            System.out.println(one.toString());
        }
    }
}
